Ext.onReady(function(){
  var Tree = Ext.tree;
   var selNode = null;
    var tree ;
     Ext.QuickTips.init();
      var form = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 180,
        defaultType: 'textfield',
        items: [new Ext.form.NumberField({
            fieldLabel: '中期检查参数修改(单位：月)',
            id:'MEMO1',
            maxLength:5,
            value:100,
            name: 'MEMO1',
            blankText:0,
            allowBlank:false,
            anchor: '100%'  // anchor width by percentage
        })]
    });

	var w=new Ext.Window({
          // contentEl:"win",//主体显示的html元素，也可以写为el:"win"
           width:450,
           height:100,
           closable:false,
           title:"中期检查参数设置",
			items: form, 
			buttons: [{
				text: '保存',
				handler:function()
				{   
				  //if(form.items.items[0].getValue() == ''){ 
					//     alert("输入不能为空");
					//     return; 
				  // } 
				  if(!form.form.isValid())
           				Ext.MessageBox.alert("提示!", "请正确填写表单!");
           		  else{
           			w.hide();
           			modiShowResultText(form.items.items[0].getValue());
					cleanForm();
					}    
				}
				 
			},{    
				text: '取消',
				handler:function()
				{
					w.hide();
					cleanForm();
				}
			}]
        });
        
        /***清楚form中数据***/
      function cleanForm(){
	      form.items.items[0].setValue('');
      }
   
// shorthand
 var accordion = new Ext.Panel({
                region:'center',
                margins:'5 0 5 5',
                split:true,
                width: 210,
                margins:'0 0 0 0',
                autoScroll:true,
                border:false,
                html:'<div id="leftTree"></div>'
            });

            var viewport = new Ext.Panel({
            	renderTo:'layout-borderlayout-main',
                layout:'border',
                margins:'0 0 0 0',
                autoWidth:true,
                height:600,
                items:[
                    accordion]
            });
  	/**
	 * 右键菜单 
	 */
  var ctxMenu = new Ext.menu.Menu({
        id:'copyCtxs',
        items: [{
                id:'orgmodi',
                handler:sortModi,
                cls:'collapse-all',
                text:'中期检查参数设置'
				}
				]
    });
	var win;
    /**添加分类**/
    /***xxigai ********/
     function modiShowResultText(MEMO1){
    	selNode.attributes.MEMO1 = MEMO1;
    	var textVal =  selNode.text;
    	var index = textVal.indexOf('<');
    	var name = textVal.substr(0,index); 
    	selNode.setText(name+'<font color=red>('+MEMO1+")</font>"); 
    	sortAjax("tagTree.htm",{id:selNode.id,action:'editSortMem',MEMO1:MEMO1},addSuE,sortFail);
    }
    /**修改成功**/
	function addSuE(){   
	   alert("操作成功");
	}
    function sortFail(){alert("操作失败!");}
    function sortModi(node){
		if(selNode == null)
			return;
		   //	 Ext.MessageBox.prompt('修改分类', '请输入分类名称:', modiShowResultText,null,null,selNode.text);
		 //  alert(selNode.attributes.MEMO1);
		 form.items.items[0].setValue(selNode.attributes.MEMO1);
		  w.show();
		   
    }

      tree = new Tree.TreePanel({
        el:'leftTree',
		autoScroll:true,
		animate:true,
		enableDD:true,
		autoHeight :true,
		border:false,
		rootVisible:true,
		allowDrag:true,
		containerScroll: true,
        loader: new Tree.TreeLoader({
             dataUrl:'tagTree.htm',
             baseParams:{id:1,action:'listSorl'}
             
        })
        
    });
    tree.on("beforeload", function(treeLoader, node) {
	 	tree.loader.baseParams.id = treeLoader.id;
    }, this);
    // set the root node
    var root = new Tree.AsyncTreeNode({
        text: '中期检查周期参数设置',
        draggable:false,
        expandable: true,
		MEMO1:'0',
        id:'1'
    });
    tree.setRootNode(root);

    // render the tree
    tree.render();
    root.expand();
    tree.on('contextmenu',prepareCtx);
   
     tree.on('click', function(node){
	     if(!node.hasChildNodes())
	     {
	     // accordion02.load('/pre/perInfo.do?perInfo=list&id='+node.id);
			 var url ='tagTree.htm?action=list&sortId='+node.id;
	      }
	       else{node.unselect();};
	});

   function prepareCtx(node, e){
        selNode = node;
        node.select();
        if(node.id != 0)
	   {
			ctxMenu.showAt(e.getXY());
		}
    }
});


function sortAjax(url,params,sucFn,faiFn){
	Ext.Ajax.request({
	   url: url,
	   success: sucFn,
	   failure: faiFn,
	   params: params
	});
}
